#!/usr/bin/env python

# To run the tests
#     TestPrimes.py

# To document the tests
#     pydoc -w TestPrimes

import main
import unittest

# ----------
# TestReader
# ----------

class TestReader (object) :
    def __init__ (self, s) :
        self.s = s

    def read (self) :
        return self.s

# ----------
# TestWriter
# ----------

class TestWriter (object) :
    def str (self) :
        return self.s

    def write (self, *a) :
        self.s = str(a[0])
        for w in a[1:] :
            self.s += ' '
            self.s += str(w)
        self.s += '\n'

# -----------
# TestCollatz
# -----------

class TestCollatz (unittest.TestCase) :
    # ----
    # read
    # ----

    def test_read (self) :
        reader = TestReader('1\n')
        main.my_read(reader)
        self.assert_(main.i ==  1)

    # ----
    # eval
    # ----

    def test_eval1 (self) :
        main.i =  1
        main.my_eval()
        self.assert_(main.out == [])

    def test_eval2 (self) :
        main.i =  -1
        main.my_eval()
        self.assert_(main.out == [])

    def test_eval3 (self) :
        main.i =  7
        main.my_eval()
        self.assert_(main.out == [])

    def test_eval4 (self) :
        main.i =  8
        main.my_eval()
        self.assert_(main.out == [2, 2, 2, 2])

    def test_eval5 (self) :
        main.i =  9
        main.my_eval()
        self.assert_(main.out == [2, 3, 2, 2])

    def test_eval6 (self) :
        main.i =  12
        main.my_eval()
        self.assert_(main.out == [2, 2, 3, 5])

    def test_eval7 (self) :
        main.i =  13
        main.my_eval()
        self.assert_(main.out == [2, 3, 3, 5])

    def test_eval8 (self) :
        main.i =  10000000
        main.my_eval()
        self.assert_(main.out == [2, 2, 5, 9999991])

    def test_eval9 (self) :
        main.i =  42
        main.my_eval()
        self.assert_(main.out == [2, 2, 7, 31])

    # -----
    # print
    # -----

    def test_print (self) :
        main.i =  1
        main.my_eval()
        writer = TestWriter()
        main.my_print(writer)
        self.assert_(writer.str() == 'Impossible.\n')

if __name__ == "__main__" :
    unittest.main()
